# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/14 19:39
# @Author   : Robot-Zsj
"""
description:

i：
3
1 1
1 2
1 3

o:
3
"""
import heapq
import sys


class Range:
    def __init__(self, start, end):
        self.start = start
        self.end = end

    def __gt__(self, other):
        if self.end != other.end:
            return other.end > self.end
        else:
            return other.start > self.start


n = int(input())

pq = []

for _ in range(n):
    start, end = map(int, input().split())
    heapq.heappush(pq, Range(start, end))


def getResult():
    count = 0

    last_end = sys.maxsize

    while len(pq) > 0:
        ran = heapq.heappop(pq)

        if ran.end < last_end:
            last_end = ran.end
            count += 1
        elif last_end > ran.start:

            ran.end = last_end - 1
            heapq.heappush(pq, ran)
    return count


print(getResult())
